import { BIGINT_PG, ExtBigIdTuple, ExtIdTuple, INTEGER_PG, VARCHAR255_PG, VARCHAR50_PG } from "~/db.pg";
import { Tradable } from "~/extend";

import { ExtOwner } from "@/stream-user/core.define";
import { TonOrder } from "@/river-ton/schema.order";
import { Voucher } from "@/river-voucher/schema.voucher";

import { ENUM_BOOK_TYPE, ENUM_BOOK_DIRECTION } from "@/pond-book/core.define";
import { Contact } from "@/pond-contact/schema.contact";

/** 某笔交易的（明细）账簿记录 */
export type Book = ExtBigIdTuple &
  ExtOwner &
  Tradable & {
    type: ENUM_BOOK_TYPE;
    direction: ENUM_BOOK_DIRECTION;
    remark: VARCHAR255_PG;

    /** 借贷平衡 */
    coupleId: VARCHAR50_PG;
    amount: INTEGER_PG;
  } & {
    justContact?: Contact;
    justTonOrder?: TonOrder;
    justVoucher?: Voucher;
  };

/** 🚚对交易记录（按时间）进行统计 */
export type BookMap = ExtBigIdTuple &
  ExtOwner &
  Tradable & {
    type: ENUM_BOOK_TYPE;
    remark: VARCHAR255_PG;

    amount: BIGINT_PG;
    amountJie: BIGINT_PG;
    amountDai: BIGINT_PG;
  } & {
    justContact?: Contact;
    justTonOrder?: TonOrder;
    justVoucher?: Voucher;
  };

/** 🚚对联系人（按时间）进行统计 */
export type BookContactMap = ExtIdTuple &
  ExtOwner &
  Tradable & {
    type: ENUM_BOOK_TYPE;
    remark: VARCHAR255_PG;

    amount: BIGINT_PG;
    amountJie: BIGINT_PG;
    amountDai: BIGINT_PG;
  } & {
    justContact?: Contact;
  };
